package com.sunda.spmsoversea.mapper;

import com.sunda.spmsoversea.entity.OverseaWhsInDtl;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 海外仓入库任务明细 Mapper 接口
 * </p>
 *
 * @author Wayne
 * @since 2021-08-26
 */
@Mapper
public interface OverseaWhsInDtlMapper extends BaseMapper<OverseaWhsInDtl> {

    /***
    @Select("SELECT OWID.AUTO_ID_WHS_IN_DTL AS \"autoIdWhsInDtl\",\n" +
            "       OWID.UUID_WHS_IN AS \"uuidWhsIn\",\n" +
            "       OWID.ITEM AS \"item\",\n" +
            "       OWID.MATERIAL_NO AS \"materialNo\",\n" +
            "       OWID.BASIC_UNIT AS \"basicUnit\",\n" +
            "       OWID.UNIT_SALES AS \"unitSales\",\n" +
            "       OWID.RECEIVABLE_QTY_BASIC_UNIT AS \"receivableQtyBasicUnit\",\n" +
            "       OWID.RECEIVABLE_QTY_UNIT_SALES AS \"receivableQtyUnitSales\",\n" +
            "       OWID.ACTUAL_QTY_BASIC_UNIT AS \"actualQtyBasicUnit\",\n" +
            "       OWID.ACTUAL_QTY_UNIT_SALES AS \"actualQtyUnitSales\",\n" +
            "       OWID.STORAGE_INFO AS \"storageInfo\",\n" +
            "       OWID.BOX_NOTE AS \"boxNote\",\n" +
            "       OWID.BOX_NOTE_ITEM AS \"boxNoteItem\",\n" +
            "       OWID.ITEM_REMARKS AS \"itemRemarks\",\n" +
            "       OWID.SAP_DELIVERY_NOTE AS \"sapDeliveryNote\",\n" +
            "       OWID.SAP_DELIVERY_NOTE_ITEM AS \"sapDeliveryNoteItem\",\n" +
            "       OWID.RECEIVABLE_WERKS AS \"receivableWerks\",\n" +
            "       OWID.RECEIVABLE_WHS_LOCATION_CODE AS \"receivableWhsLocationCode\",\n" +
            "       OWID.ACTUAL_WERKS AS \"actualWerks\",\n" +
            "       OWID.ACTUAL_WHS_LOCATION_CODE AS \"actualWhsLocationCode\",\n" +
            "       OPLB.DEMAND_NO AS \"demandNo\",\n" +
            "       OPLB.DEMAND_ITEM AS \"demandItem\",\n" +
            "       OPLB.DEMANDER AS \"demander\",\n" +
            "       SAP.MATERIAL_ZH_DESC AS \"materialZhDesc\",\n" +
            "       SAP.MATERIAL_EN_DESC AS \"materialEnDesc\",\n" +
            "       (CASE WHEN SAP.NUMERATOR IS NULL THEN 1 ELSE SAP.NUMERATOR END) AS \"numerator\",\n" +
            "       (CASE WHEN SAP.DENOMINATOR IS NULL THEN 1 ELSE SAP.DENOMINATOR END) AS \"denominator\"\n" +
            "FROM OVERSEA_WHS_IN_DTL OWID\n" +
            "    LEFT JOIN MATERIAL_SAP SAP ON OWID.MATERIAL_NO = SAP.MATERIAL_NO " +
            "    LEFT JOIN OVERSEA_PACKAGE_LIST_BOX OPLB ON OWID.BOX_NOTE = OPLB.BOX_NOTE " +
            "       AND OWID.BOX_NOTE_ITEM = OPLB.BOX_NOTE_ITEM\n" +
            "WHERE OWID.UUID_WHS_IN = #{uuidWhsIn}\n" +
            "ORDER BY OWID.AUTO_ID_WHS_IN_DTL ASC \n")
    List<Map<String, Object>> getOverseaWhsInDtlList(@Param("uuidWhsIn") String uuidWhsIn);
     获取海运入库任务明细时，通过需求单号+需求行号关联出原车间请购单相关信息 使用以下接口替换。———— 20220218
     ***/

    @Select("SELECT OWID.AUTO_ID_WHS_IN_DTL AS \"autoIdWhsInDtl\",\n" +
            "       OWID.UUID_WHS_IN AS \"uuidWhsIn\",\n" +
            "       OWID.ITEM AS \"item\",\n" +
            "       OWID.MATERIAL_NO AS \"materialNo\",\n" +
            "       OWID.BASIC_UNIT AS \"basicUnit\",\n" +
            "       OWID.UNIT_SALES AS \"unitSales\",\n" +
            "       OWID.RECEIVABLE_QTY_BASIC_UNIT AS \"receivableQtyBasicUnit\",\n" +
            "       OWID.RECEIVABLE_QTY_UNIT_SALES AS \"receivableQtyUnitSales\",\n" +
            "       OWID.ACTUAL_QTY_BASIC_UNIT AS \"actualQtyBasicUnit\",\n" +
            "       OWID.ACTUAL_QTY_UNIT_SALES AS \"actualQtyUnitSales\",\n" +
            "       OWID.STORAGE_INFO AS \"storageInfo\",\n" +
            "       OWID.BOX_NOTE AS \"boxNote\",\n" +
            "       OWID.BOX_NOTE_ITEM AS \"boxNoteItem\",\n" +
            "       OWID.ITEM_REMARKS AS \"itemRemarks\",\n" +
            "       OWID.SAP_DELIVERY_NOTE AS \"sapDeliveryNote\",\n" +
            "       OWID.SAP_DELIVERY_NOTE_ITEM AS \"sapDeliveryNoteItem\",\n" +
            "       OWID.RECEIVABLE_WERKS AS \"receivableWerks\",\n" +
            "       OWID.RECEIVABLE_WHS_LOCATION_CODE AS \"receivableWhsLocationCode\",\n" +
            "       OWID.ACTUAL_WERKS AS \"actualWerks\",\n" +
            "       OWID.ACTUAL_WHS_LOCATION_CODE AS \"actualWhsLocationCode\",\n" +
            "       OPLB.DEMAND_NO AS \"demandNo\",\n" +
            "       OPLB.DEMAND_ITEM AS \"demandItem\",\n" +
            "       OPLB.DEMANDER AS \"demander\",\n" +
            "       SAP.MATERIAL_ZH_DESC AS \"materialZhDesc\",\n" +
            "       SAP.MATERIAL_EN_DESC AS \"materialEnDesc\",\n" +
            "       (CASE WHEN SAP.NUMERATOR IS NULL THEN 1 ELSE SAP.NUMERATOR END) AS \"numerator\",\n" +
            "       (CASE WHEN SAP.DENOMINATOR IS NULL THEN 1 ELSE SAP.DENOMINATOR END) AS \"denominator\",\n" +
            "       OWD.SPMS_WS_ID AS \"spmsWsId\",\n" +
            "       OWD.ROW_ID_WS AS \"rowIdWs\",\n" +
            "       OW.WORKSHOP_CODE AS \"workshopCode\",\n" +
            "       OW.WORK_CODE AS \"userId\",\n" +
            "       U.LAST_NAME AS \"username\"\n" +
            "FROM OVERSEA_WHS_IN_DTL OWID\n" +
            "    LEFT JOIN MATERIAL_SAP SAP ON OWID.MATERIAL_NO = SAP.MATERIAL_NO\n" +
            "    LEFT JOIN OVERSEA_PACKAGE_LIST_BOX OPLB ON OWID.BOX_NOTE = OPLB.BOX_NOTE AND OWID.BOX_NOTE_ITEM = OPLB.BOX_NOTE_ITEM\n" +
            "    LEFT JOIN ORDER_WERKS_DTL OWD ON OPLB.DEMAND_NO = OWD.SPMS_ID AND OPLB.DEMAND_ITEM = OWD.ROW_ID_WERKS\n" +
            "    LEFT JOIN ORDER_WORKSHOP OW ON OWD.SPMS_WS_ID = OW.SPMS_WS_ID\n" +
            "    LEFT JOIN SPMS_USER U ON OW.WORK_CODE = U.WORK_CODE\n" +
            "WHERE OWID.UUID_WHS_IN = #{uuidWhsIn}\n" +
            "ORDER BY OWID.AUTO_ID_WHS_IN_DTL ASC")
    List<Map<String, Object>> getOverseaWhsInDtlList(@Param("uuidWhsIn") String uuidWhsIn);
}


